//
//  UIImage+Runtime.m
//  Runtime
//
//  Created by 李少葵 on 27/1/16.
//  Copyright © 2016年 myClassroom. All rights reserved.
//

#import "UIImage+Runtime.h"
#import <objc/message.h>

@implementation UIImage (Runtime)

-(void)load{
    //交换方法,load 在main函数加载之前就调用了,且保证只加载一次
    Method imageWithName = class_getClassMethod([self class], @selector(imageWithName:));
    Method imageName = class_getClassMethod([self class], @selector(imageNamed:));
    method_exchangeImplementations(imageName, imageWithName);
}


//self defined method to exchange the method of the system
+ (UIImage *) imageWithName:(NSString *)image{
    UIImage *tempImage = [UIImage imageNamed:image];
    if (!tempImage) {
        NSLog(@"图片地址错误,资源不存在");
    }else{
        
        NSLog(@"下载成功..");
    }

    return tempImage;
}








@end
